package com.niit.project.controller;

import com.niit.project.service.GoodsService;
import com.niit.project.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

//张雨佳——封禁商品
@WebServlet(name = "DeleteGoodsController", value = "/DeleteGoodsController")
public class DeleteGoodsController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取前端传来的商品名goodname
        String goodname = request.getParameter("goodname");
        GoodsService goodsService = new GoodsServiceImpl();
        //调用删除商品方法,通过商品名删除的,因为时非主键删除,所以需要将mysql的安全模式关闭,具体方法可自行搜索
        goodsService.deleteGoods(goodname);
        System.out.println("封禁成功！");
        //重定向到展示所有商品信息的servelt文件
        response.sendRedirect(request.getContextPath()+"/ShowAllGoodsController");
    }
}
